import { create } from "dva-core-ts";
import models from "@/models/index";
import { createHashHistory } from "history";
import { connectRouter, routerMiddleware } from "connected-react-router";

export const history = createHashHistory();

// console.log(history);
const routerReducer = connectRouter(history);
const routerMiddlewareForDispatch = routerMiddleware(history);

// 1.创建实例
const app = create({
  // @ts-ignore
  extraReducers: { router: routerReducer }, //嵌入路由reducer,暂时不知道泛型该咋用啥,所以暂时禁用
  // onAction: [routerMiddlewareForDispatch],
});

// 2.加载model对象
models.forEach((model) => {
  app.model(model);
});
// app
// 3.启动dva
app.start();
// console.log(app);
// 4.导出dva的数据
export default app._store;
